<template>
  <div>
    <!-- 参数区域 -->
    <portal-param-view ref="paramViewForm" :showSearchBtn="false" :pms="pms"></portal-param-view>
    <!-- 组件区域 -->
    <layout-view ref="optarea" :pageInfo="pageInfo"></layout-view>
  </div>
</template>

<script>
import request from "@/utils/request"
import {Loading} from "element-ui";
import LayoutView from './LayoutView.vue'
import PortalParamView from './PortalParamView.vue'

export default {
  data() {
    return {
      reportId: null,
      pageInfo: {},
      pms: []
    }
  },
  components: {
    LayoutView,
    PortalParamView
  },
  mounted() {
    window.document.title = "报表打印";
    this.reportId = this.$route.query.id;
    this.getCfg();
  },
  beforeDestroy() {

  },
  computed: {},
  methods: {
    getCfg() {
      request({
        url: "/bi/portal/get",
        params: {pageId: this.reportId},
        method: "get",
      }).then(resp => {
        this.pageInfo = JSON.parse(resp.rows);
        //初始化参数字段
        let urlParam = JSON.parse(JSON.stringify(this.$route.query));
        delete urlParam.id;
        this.$refs['paramViewForm'].initReportParam(urlParam, this.pageInfo.params);
        this.getReport(urlParam);
      });
    },
    getReport(urlParam) {
      urlParam.pageId = this.reportId;
      let loadingInstance = Loading.service({
        fullscreen: false,
        target: document.querySelector('.wrapper-content-nomargin')
      });
      request({
        url: "/bi/portal/view",
        method: "GET",
        params: urlParam,
      }).then(resp => {
        this.pms = resp.rows.pms;
        //渲染组件
        this.$refs['optarea'].setCompData(resp.rows);
        this.$nextTick(() => {
          window.print();
        });
      });
    }
  },
  watch: {}
}
</script>
